﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace qqdest.utils
{
    public static class RandomUtil
    {
        /// <summary>
        /// 随机生成指定长度的数字字符串
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string GenerateRandomDigits(int length)
        {
           if (length <= 0)
                throw new ArgumentException("长度必须大于 0", nameof(length));

            const string digits = "0123456789";
            StringBuilder result = new StringBuilder(length);
            Random random = new Random();

            // 确保第一位数字不为 0（如果需要避免以 0 开头）
            if (length > 0)
                result.Append(digits[random.Next(1, 10)]);

            // 生成剩余的数字
            for (int i = 1; i < length; i++)
                result.Append(digits[random.Next(0, 10)]);

            return result.ToString();
        }
    }
}
